var commons = {
	categories : {
		'Home': {
			regularStuffs: {
				name	: 'Grocery',
				id		: 'HO01',
				icon	: 'fugue/shopping-basket.png',
				desc	: 'none'
			},
			meat: {
				name	: 'Meat',
				id		: 'HO02',
				icon	: 'fugue/exclamation-diamond.png',
				desc	: 'none'
			},
			oneTimeStuffs: {
				name	: 'One Time Stuffs',
				id		: 'HO03',
				icon	: 'fugue/sofa.png',
				desc	: 'none'
			},
			other: {
				name	: 'Home Other',
				id		: 'HO04',
				icon	: 'fugue/exclamation-diamond.png',
				desc	: 'none'
			},
			maintenance: {
				name	: 'Home Maintenance',
				id		: 'HO05',
				icon	: 'fugue/broom.png',
				desc	: 'none'
			}
		},
		'Education' : {
			booksAndCDs: {
				name	: 'Books and CDs',
				id		: 'ED01',
				icon	: 'fugue/book-open.png',
				desc	: 'none'
			}
		},
		'Clothes' : {
			femaleClothes: {
				name	: 'Female Clothes',
				id		: 'CL01',
				icon	: 'fugue/toilet-female.png',
				desc	: 'none'
			},
			maleClothes: {
				name	: 'Male Clothes',
				id		: 'CL02',
				icon	: 'fugue/toilet-male.png',
				desc	: 'none'
			}
		},
		'Work': {
			workExpenses: {
				name	: 'Work Expenses',
				id		: 'WE01',
				icon	: 'fugue/briefcase.png',
				desc	: 'none'
			}
		},
		'Car': {
			fuel: {
				name	: 'Fuel',
				id		: 'CA01',
				icon	: 'fugue/car.png',
				desc	: 'none'
			},
			installment: {
				name	: 'Installment',
				id		: 'CA02',
				icon	: 'fugue/money-coin.png',
				desc	: 'none'
			},
			maintenance: {
				name	: 'Maintenance',
				id		: 'CA03',
				icon	: 'fugue/wrench-screwdriver.png',
				desc	: 'none'
			},
			salik: {
				name	: 'Salik',
				id		: 'CA04',
				icon	: 'fugue/exclamation-diamond.png',
				desc	: 'none'
			},
			other: {
				name	: 'Car Other',
				id		: 'CA05',
				icon	: 'fugue/exclamation-diamond.png',
				desc	: 'none'
			}
		},
		'Payments': {
			homeCheck: {
				name	: 'Home Check',
				id		: 'PA01',
				icon	: 'fugue/home.png',
				desc	: 'none'
			},
			dewa: {
				name	: 'DEWA',
				id		: 'PA02',
				icon	: 'fugue/socket.png',
				desc	: 'none'
			},
			du: {
				name	: 'DU',
				id		: 'PA03',
				icon	: 'fugue/mobile-phone-off.png',
				desc	: 'none'
			},
			etisalat: {
				name	: 'Etisalat',
				id		: 'PA04',
				icon	: 'fugue/exclamation-diamond.png',
				desc	: 'none'
			},
			other: {
				name	: 'Payments Other',
				id		: 'PA05',
				icon	: 'fugue/exclamation-diamond.png',
				desc	: 'none'
			}
		},
		'Medical': {
			drug: {
				name	: 'Drug',
				id		: 'ME01',
				icon	: 'pill.png',
				desc	: 'none'
			},
			medicine: {
				name	: 'Medicine',
				id		: 'ME02',
				icon	: 'FirstAidKit.png',
				desc	: 'none'
			},
			other: {
				name	: 'Medical Other',
				id		: 'ME03',
				icon	: 'fugue/exclamation-diamond.png',
				desc	: 'none'
			}
		},
		'Entertainment': {
			food: {
				name	: 'Food',
				id		: 'EN01',
				icon	: 'fugue/cutlery.png',
				desc	: 'none'
			},
			cinema: {
				name	: 'Cinema',
				id		: 'EN02',
				icon	: 'fugue/film.png',
				desc	: 'none'
			},
			trips: {
				name	: 'Trips',
				id		: 'EN03',
				icon	: 'fugue/exclamation-diamond.png',
				desc	: 'none'
			},
			other: {
				name	: 'Entertainment Other',
				id		: 'EN04',
				icon	: 'fugue/exclamation-diamond.png',
				desc	: 'none'
			},
			duty: {
				name	: 'Duty Call',
				id		: 'EN05',
				icon	: 'fugue/users.png',
				desc	: 'none'
			}
		}
		/*medical : {
			name: 'Medical',
			id	: 'ME-01',
			icon: 'none',
			desc: 'none'
		},
		automobile: {
			name: 'Car',
			id	: 'CA-01',
			icon: 'none',
			desc: 'none',
		},
		food : {
			name: 'Food',
			id	: 'FO-01',
			icon: 'none',
			desc: 'none'
		},
		entertainment: {
			name: 'Entertainment',
			id	: 'EN-01',
			icon: 'none',
			desc: 'none'
		},
		maintenance: {
			name: 'Maintenance',
			id	: 'MA-01',
			icon: 'none',
			desc: 'none'
		}*/
	},
	attributes : {
		category: 'data-category',
		date: 'data-time',
		amount: 'data-amount'
	},
	constants: {
		icons: 'fugue/exclamation-diamond.png'
	}
};

/*var lwData = {
	records: {
		/*'r_###': {	
				category: commons.categories.Medical.id,
				description: 'database is empty',
				amount: 0,
				date: (new Date().getTime())
		}
	}
};*/

function getCategoryName(id) {
	for (var cat in commons.categories) {
		for(var incat in eval('commons.categories.'+cat)) {
			if(eval('commons.categories.' + cat + '.' + incat +'.id') == id) {
				return eval('commons.categories.' + cat + '.' + incat + '.name');
			}
		}
	}
	return undefined;
}

function getCategoryIcon(id) {
	for (var cat in commons.categories) {
		for(var incat in eval('commons.categories.'+cat)) {
			if(eval('commons.categories.' + cat + '.' + incat +'.id') == id) {
				return eval('commons.categories.' + cat + '.' + incat + '.icon');
			}
		}
	}
	return undefined;
}

function transformString(dateStr) {
	var dateEls = dateStr.split('-');
	var date = new Date();
	date.setDate(parseInt(dateEls[0]));
	date.setMonth(parseInt(dateEls[1])-1);
	date.setFullYear(parseInt(dateEls[2]));
	return date.getTime();
}

function getDate(date) {
	var arr = date.split('-');
	return getStandardDate(arr[2], arr[1], arr[0]).getTime();
}

function getStandardDate(year, month, day) {
	var date = new Date(parseInt(year, 10), (parseInt(month, 10)-1), parseInt(day, 10), 1, 1, 1, 1);
	return date;
}

function transformTime(time) {
	var sep = '-'
	var date = new Date();
	date.setTime(time);
	var years  = date.getFullYear();
	var months = date.getMonth()+1;
	var days = date.getDate();
	return (days < 10 ? '0'+days : days) + sep + (months < 10 ? '0'+months : months) + sep + years; 
}

//* just a simple way to avoid javascript crashing in case client browser does not have console turned on
function log(obj) {
	if(typeof console != 'undefined' && typeof console != null)
		console.log(obj);
}

// usage: log('inside coolFunc',this,arguments);
/*/ paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console){
    console.log( Array.prototype.slice.call(arguments) );
  }
}; //*/
